import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;
import javax.swing.JScrollPane;
import javax.swing.JList;
import javax.swing.JTextArea;
import javax.swing.JTree;
import javax.swing.JComboBox;
import javax.swing.JSeparator;
import javax.swing.DropMode;

/**
 * Fenêtre de consultation d'un ouvrage Code du JFrame généré par Window
 * Builder/Swing Designer.
 * 
 * @author IUT, A.Culet
 * @version 1.0
 */

public class VueConsultPeriodique extends Vue {

	private JPanel contentPane;
	private JTextField textFieldIssn;

	// pour que les boutons soient des attributs, il faut faire
	// "convert local to field"
	private JButton buttonRech;
	private JButton buttonAnnuler;
	private JButton buttonFermer;

	private final JSeparator separator = new JSeparator();
	private JTextField textField;
	private JTextField textField_1;
	private	JTextArea textAreainfoParution;
	/**
	 * Create the frame.
	 */
	public VueConsultPeriodique(Controleur controleur) {
		super(controleur);
		setTitle("Informations sur un Periodique");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 589);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel lblNewLabel = new JLabel("Issn");
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setBounds(17, 66, 61, 15);
		contentPane.add(lblNewLabel);

		textFieldIssn = new JTextField();
		textFieldIssn.setBounds(112, 64, 114, 19);
		contentPane.add(textFieldIssn);
		textFieldIssn.setColumns(10);

		buttonAnnuler = new JButton("Annuler");
		buttonAnnuler.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().fermerVue(VueConsultPeriodique.this);
			}
		});
		buttonAnnuler.setBounds(255, 98, 107, 25);
		contentPane.add(buttonAnnuler);

		buttonRech = new JButton("Rechercher");
		buttonRech.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().rechPeriodique2(textFieldIssn.getText());
			}
		});
		buttonRech.setBounds(255, 61, 107, 25);
		contentPane.add(buttonRech);

		buttonFermer = new JButton("Fermer");
		buttonFermer.setEnabled(false);
		buttonFermer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().fermerVue(VueConsultPeriodique.this);
			}
		});
		

		buttonFermer.setBounds(167, 504, 107, 25);
		contentPane.add(buttonFermer);
		
		JLabel lblParution = new JLabel("Parution");
		lblParution.setBounds(49, 164, 54, 15);
		contentPane.add(lblParution);
		separator.setBounds(10, 135, 414, 33);
		contentPane.add(separator);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(61, 207, 325, 96);
		contentPane.add(scrollPane);
		
		
		JTextArea textAreainfoParution = new JTextArea();
		textAreainfoParution.setEditable(false);
		textAreainfoParution.setWrapStyleWord(true);
		scrollPane.setColumnHeaderView(textAreainfoParution);
		
		
		JSeparator separator_1 = new JSeparator();
		separator_1.setBounds(17, 362, 407, 33);
		contentPane.add(separator_1);
		
		JLabel lblTitre = new JLabel("Titre");
		lblTitre.setHorizontalAlignment(SwingConstants.RIGHT);
		lblTitre.setBounds(42, 405, 61, 15);
		contentPane.add(lblTitre);
		
		textField = new JTextField();
		textField.setEditable(false);
		textField.setBounds(160, 405, 202, 21);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel lblFrequence = new JLabel("Frequence");
		lblFrequence.setHorizontalAlignment(SwingConstants.RIGHT);
		lblFrequence.setBounds(49, 445, 61, 15);
		contentPane.add(lblFrequence);
		
		textField_1 = new JTextField();
		textField_1.setEditable(false);
		textField_1.setBounds(160, 442, 202, 21);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
	}


	/**
	 * alimentation des composants d'affichage en consultant directement
	 * l'ouvrage
	 */
	public void alimente(Periodique per) {
		
		textField.setText(per.getTitre());
		textField_1.setText(per.getFrequence());
		


	}
	

	/**
	 * définition des états de la fenêtre, cad des régions actives selon l'état
	 */
	public void setEtat(int etat) {
		switch (etat) {
		case initiale: {
			buttonRech.setEnabled(true);
			buttonAnnuler.setEnabled(true);
			
			textField.setEnabled(false);
			textField_1.setEnabled(false);
			buttonFermer.setEnabled(false);

			break;
		}

		case finale: {
			buttonRech.setEnabled(false);
			buttonAnnuler.setEnabled(false);

			textField.setEnabled(true);
			textField_1.setEnabled(true);
			buttonFermer.setEnabled(true);
			break;
		}
		}
	}
}
